package top.yongyan0624.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import top.yongyan0624.common.lang.Result;
import top.yongyan0624.entity.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yongyan
 * @since 2021-09-15
 */
@RestController
@RequestMapping("/property/pay/project")
public class PropertyPayProjectController extends BaseController {
    @GetMapping("/list")
    public Result list(){
        List<PropertyPayProject> projectList = propertyPayProjectService.list();

        return Result.success(projectList);
    }

    @PostMapping("/save")
    public Result save(@RequestBody PropertyPayProject project){
        propertyPayProjectService.save(project);

        return Result.success(project);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('payProject:update')")
    public Result update(@RequestBody PropertyPayProject project){
        propertyPayProjectService.updateById(project);

        return Result.success(project);
    }

    @Transactional
    @PostMapping("/delete")
    @PreAuthorize("hasAuthority('payProject:delete')")
    public Result delete(@RequestBody Long[] ids) {
        propertyPayProjectService.removeByIds(Arrays.asList(ids));
        propertyPayService.remove(new QueryWrapper<PropertyPay>().in("project_id", ids));

        return Result.success("");
    }
}
